import Vue from "vue";
import Router from "vue-router";
import Home from "./views/Home.vue";

Vue.use(Router);

const router = new Router({
  mode: "hash",
  base: process.env.BASE_URL,
  routes: [
    {
      path: "/",
      name: "home",
      meta: {
        title: "首页"
      },
      component: () => import("@/views/Home.vue"),
      children: [
        {
          path: "/dynamics",
          name: "dynamics",
          meta: {
            title: "视频",
            keepAlive: true,
            hasBack: false,
            homePage: true
          },
          component: () => import("@/views/dynamics/dynamics.vue")
        },
        {
          path: "/mall",
          name: "mall",
          meta: {
            title: "飞宝商城",
            hasBack: false,
            homePage: true
          },
          component: () => import("@/views/mall/mall.vue")
        },
        {
          path: "/vip",
          name: "vip",
          meta: {
            title: "邀请VIP",
            hasBack: false,
            homePage: true
          },
          component: () => import("@/views/vip/vip.vue")
        },
        {
          path: "/cart",
          name: "cart",
          meta: {
            title: "购物车",
            hasBack: false,
            homePage: true
          },
          component: () => import("@/views/mall/cart.vue")
        },
        {
          path: "/profile",
          name: "profile",
          meta: {
            title: "个人中心",
            hasBack: false,
            homePage: true
          },
          component: () => import("@/views/profile/profile.vue")
        }
      ]
    },
    {
      path: "/login",
      name: "login",
      redirect: "/main-login",
      meta: {
        title: "登录"
      },
      component: () => import("@/views/login/login-parent-view.vue"),
      children: [
        {
          path: "/main-login",
          name: "mainLogin",
          meta: {
            title: "登录"
          },
          component: () => import("@/views/login/main-login.vue")
        },
        {
          path: "/mobile-login",
          name: "mobileLogin",
          meta: {
            title: "登录"
          },
          component: () => import("@/views/login/mobile-login.vue")
        },
        {
          path: "/register",
          name: "register",
          meta: {
            title: "注册"
          },
          component: () => import("@/views/login/register.vue")
        }
      ]
    },
    {
      path: "/psw-reset",
      name: "pswReset",
      meta: {
        title: "忘记密码"
      },
      component: () => import("@/views/login/psw-reset.vue")
    },
    {
      path: "/new-dynamics",
      name: "newDynamics",
      meta: {
        title: "发动态"
      },
      component: () => import("@/views/dynamics/new-dynamics.vue")
    },
    {
      path: "/new-dynamics-video",
      name: "newDynamicsVideo",
      meta: {
        title: "发视频",
        keepAlive: true
      },
      component: () => import("@/views/dynamics/new-dynamics-video.vue")
    },
    {
      path: "/choose-location",
      name: "chooseLocation",
      meta: {
        title: "所在位置"
      },
      component: () => import("@/views/dynamics/choose-location.vue")
    },
    {
      path: "/choose-category",
      name: "chooseCategory",
      meta: {
        title: "选择分类"
      },
      component: () => import("@/views/dynamics/choose-category.vue")
    },
    {
      path: "/dynamics-detail",
      name: "dynamicsDetail",
      meta: {
        title: "动态详情"
      },
      component: () => import("@/views/dynamics/dynamics-detail.vue")
    },
    {
      path: "/article-detail",
      name: "articleDetail",
      meta: {
        title: "文章详情"
      },
      component: () => import("@/views/dynamics/article-detail.vue")
    },
    {
      path: "/video-detail",
      name: "videoDetail",
      meta: {
        title: "动态详情",
        hasBack: false
      },
      component: () => import("@/views/dynamics/video-detail.vue")
    },
    {
      path: "/user-page",
      name: "userPage",
      meta: {
        title: "用户主页"
      },
      component: () => import("@/views/dynamics/user-page.vue")
    },
    {
      path: "/search",
      name: "search",
      meta: {
        title: "搜索"
      },
      component: () => import("@/views/mall/search/search.vue")
    },
    {
      path: "/search-video",
      name: "SearchVideo",
      meta: {
        title: "搜索"
      },
      component: () => import("@/views/mall/search/search-video.vue")
    },
    {
      path: "/category",
      name: "category",
      meta: {
        title: "分类"
      },
      component: () => import("@/views/mall/category.vue")
    },
    {
      path: "/item-list/:id",
      name: "itemList",
      meta: {
        title: "分类商品"
      },
      component: () => import("@/views/mall/item-list.vue")
    },
    {
      path: "/notice-detail",
      name: "NoticeDetail",
      meta: {
        title: "头条详情"
      },
      component: () => import("@/components/notice-detail.vue")
    },
    {
      path: "/point-good-list",
      name: "PointGoodList",
      meta: {
        title: "积分商品"
      },
      component: () => import("@/views/mall/item-list.vue")
    },
    {
      path: "/brand-item-list/:id",
      name: "brandItemList",
      meta: {
        title: "品牌商品"
      },
      component: () => import("@/views/mall/brand-item-list.vue")
    },
    {
      path: "/vip-item",
      name: "vipItem",
      meta: {
        title: "会员商品"
      },
      component: () => import("@/views/mall/vip-item.vue")
    },
    {
      path: "/coupon",
      name: "coupon",
      meta: {
        title: "领券专区"
      },
      component: () => import("@/views/mall/coupon.vue")
    },
    {
      path: "/item-detail/:itemId",
      name: "itemDetail",
      meta: {
        title: "服务详情",
        hasBack: false
      },
      component: () => import("@/views/mall/item-detail.vue")
    },
    {
      path: "/payment",
      name: "payment",
      meta: {
        title: "确认订单"
      },
      component: () => import("@/views/mall/payment.vue")
    },
    {
      path: "/service-time",
      name: "serviceTime",
      meta: {
        title: "选择时间"
      },
      component: () => import("@/views/mall/service-time.vue")
    },
    {
      path: "/address",
      name: "address",
      meta: {
        title: "新增地址"
      },
      component: () => import("@/views/profile/address.vue")
    },
    {
      path: "/profile-edit",
      name: "profileEdit",
      meta: {
        title: "编辑资料"
      },
      component: () => import("@/views/profile/profile-edit.vue")
    },
    {
      path: "/my-dynamics",
      name: "myDynamics",
      meta: {
        title: "我的动态"
      },
      component: () => import("@/views/profile/my-dynamics.vue")
    },
    {
      path: "/my-follow",
      name: "myFollow",
      meta: {
        title: "我的关注"
      },
      component: () => import("@/views/profile/my-follow.vue")
    },
    {
      path: "/my-coupon",
      name: "myCoupon",
      meta: {
        title: "我的优惠券"
      },
      component: () => import("@/views/profile/my-coupon.vue")
    },
    {
      path: "/my-favorite",
      name: "myFavorite",
      meta: {
        title: "我的收藏"
      },
      component: () => import("@/views/profile/my-favorite.vue")
    },
    {
      path: "/addr-mng",
      name: "addrMng",
      meta: {
        title: "我的收货地址"
      },
      component: () => import("@/views/profile/addr-mng.vue")
    },
    {
      path: "/msg-center",
      name: "msgCenter",
      meta: {
        title: "消息中心"
      },
      component: () => import("@/views/profile/msg-center.vue")
    },
    {
      path: "/sys-notice",
      name: "sysNotice",
      meta: {
        title: "系统通知"
      },
      component: () => import("@/views/profile/sys-notice.vue")
    },
    {
      path: "/commission-msg",
      name: "commissionMsg",
      meta: {
        title: "佣金消息"
      },
      component: () => import("@/views/profile/commission-msg.vue")
    },
    {
      path: "/support",
      name: "support",
      meta: {
        title: "联系客服"
      },
      component: () => import("@/views/profile/support.vue")
    },
    {
      path: "/user-point",
      name: "userPoint",
      meta: {
        title: "我的积分"
      },
      component: () => import("@/views/profile/user-point.vue")
    },
    {
      path: "/express",
      name: "express",
      meta: {
        title: "物流助手"
      },
      component: () => import("@/views/profile/express.vue")
    },
    {
      path: "/my-fans",
      name: "myFans",
      meta: {
        title: "我的粉丝"
      },
      component: () => import("@/views/profile/my-fans.vue")
    },
    {
      path: "/receive-comment",
      name: "receiveComment",
      meta: {
        title: "我的粉丝"
      },
      component: () => import("@/views/profile/receive-comment.vue")
    },
    {
      path: "/orders",
      name: "orders",
      meta: {
        title: "我的订单"
      },
      component: () => import("@/views/profile/order/order.vue")
    },
    {
      path: "/order-detail",
      name: "orderDetail",
      meta: {
        title: "我的订单"
      },
      component: () => import("@/views/profile/order/order-detail.vue")
    },
    {
      path: "/represent-orders",
      name: "RepresentOrder",
      meta: {
        title: "代言订单"
      },
      component: () => import("@/views/profile/order/represent-order.vue")
    },
    {
      path: "/represent-order-detail",
      name: "RepresentOrderDetail",
      meta: {
        title: "我的订单"
      },
      component: () => import("@/views/profile/order/represent-order-detail.vue")
    },
    {
      path: "/my-represent-orders",
      name: "RepresentOrders",
      meta: {
        title: "我的代言"
      },
      component: () => import("@/views/profile/order/my-represent-order.vue"),
      children: [{
        path: 'my-represent-detail',
        name: 'MyRepresentDetail',
        meta: {
          title: '代言详情',
          hasBack: true
        },
        component: () => import("@/views/represent/my-represent-detail.vue")
      }]
    },
    {
      path: "/express-detail",
      name: "expressDetail",
      meta: {
        title: "物流详情"
      },
      component: () => import("@/views/profile/order/express-detail.vue")
    },
    {
      path: "/order/comment",
      name: "itemComment",
      meta: {
        title: "发布评价"
      },
      component: () => import("@/views/profile/order/comment.vue")
    },
    {
      path: "/order/after-sale",
      name: "afterSale",
      meta: {
        title: "退货退款"
      },
      component: () => import("@/views/profile/order/after-sale.vue")
    },
    {
      path: "/pay-succ",
      name: "paySucc",
      meta: {
        title: "支付结果",
        hasBack: false,
      },
      component: () => import("@/views/mall/pay-succ.vue")
    },
    {
      path: "/income-detail",
      name: "incomeDetail",
      meta: {
        title: "收益明细"
      },
      component: () => import("@/views/vip/income-detail.vue")
    },
    {
      path: "/income-item-detail",
      name: "incomeItemDetail",
      meta: {
        title: "收益明细"
      },
      component: () => import("@/views/vip/income-item-detail.vue")
    },
    {
      path: "/wait-to-recorded",
      name: "waitToRecorded",
      meta: {
        title: "待入账"
      },
      component: () => import("@/views/vip/be-recorded.vue")
    },
    {
      path: "/balance",
      name: "balance",
      meta: {
        title: "余额"
      },
      component: () => import("@/views/vip/balance.vue")
    },
    {
      path: "/balance-detail",
      name: "balanceDetail",
      meta: {
        title: "余额明细"
      },
      component: () => import("@/views/vip/balance-detail.vue")
    },
    {
      path: "/recomrewards",
      name: "recomrewards",
      meta: {
        title: "推荐奖励"
      },
      component: () => import("@/views/vip/recom-rewards.vue")
    },
    {
      path: "/agent-zs",
      name: "AgentZs",
      meta: {
        title: "代理招商"
      },
      component: () => import("@/views/mall/agent-zs.vue")
    },
    {
      path: "/vip-protocol",
      name: "VipProtocal",
      meta: {
        title: "会员协议"
      },
      component: () => import("@/views/mall/vip-protocol.vue")
    },
    {
      path: "/shopping-reward",
      name: "shoppingReward",
      meta: {
        title: "购物收益"
      },
      component: () => import("@/views/vip/shopping-profit.vue")
    },
    {
      path: "/my-team",
      name: "myTeam",
      meta: {
        title: "我的团队"
      },
      component: () => import("@/views/vip/my-team.vue")
    },
    {
      path: "/my-tutor",
      name: "myTutor",
      meta: {
        title: "我的导师"
      },
      component: () => import("@/views/vip/my-tutor.vue")
    },
    {
      path: "/vip-invite",
      name: "invite",
      meta: {
        title: "邀请VIP"
      },
      component: () => import("@/views/vip/invite.vue")
    },
    {
      path: "/vip-equity",
      name: "vipEquity",
      meta: {
        title: "VIP权益"
      },
      component: () => import("@/views/vip/vip-equity.vue")
    },
    {
      path: "/business-school",
      name: "businessSchool",
      meta: {
        title: "商学院"
      },
      component: () => import("@/views/vip/business-school.vue")
    },
    {
      path: "/business-detail",
      name: "businessDetail",
      meta: {
        title: "商学院详情"
      },
      component: () => import("@/views/vip/business-school-detail.vue")
    },
    {
      path: "/user-coupon",
      name: "userCoupon",
      meta: {
        title: "我的优惠券"
      },
      component: () => import("@/views/profile/user-coupon.vue")
    },
    {
      path: "/real-name-auth",
      name: "realNameAuth",
      meta: {
        title: "实名认证"
      },
      component: () => import("@/views/vip/real-name-auth.vue")
    },
    {
      path: "/my-qrcode",
      name: "MyQrcode",
      meta: {
        title: "专属二维码"
      },
      component: () => import("@/views/profile/my-qrcode.vue")
    },
    {
      path: "/represent",
      name: "Represent",
      meta: {
        title: "专属二维码"
      },
      component: () => import("@/views/represent")
    }
    // {
    //   path: '/avatar-edit',
    //   name: 'avatarEdit',
    //   meta: {
    //     title: '头像编辑'
    //   },
    //   component: () => import('@/views/profile/avatar-edit.vue')
    // }
  ],
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition && to.meta.keepAlive) {
      return savedPosition;
    }
    return {
      x: 0,
      y: 0
    };
  }
});
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  next();
});
export default router;
